package com.chunfeng.controller;

import com.chunfeng.entity.Role;
import com.chunfeng.result.JsonRequest;
import com.chunfeng.result.ServiceController;
import com.chunfeng.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 角色Controller
 *
 * @author by 春风能解释
 * <p>
 * 2022/12/20
 */
@RestController
@RequestMapping("/role")
public class RoleController extends ServiceController {

    /**
     * 角色业务层注入
     */
    @Autowired
    private IRoleService roleService;

    /**
     * 查看所有角色信息
     *
     * @return JSON
     */
    @GetMapping
    public JsonRequest<List<Role>> lookAllRoles() {
        return roleService.lookAllRoles();
    }

    /**
     * 按名称获取角色信息
     *
     * @param roleName 角色名
     * @return JSON
     */
    @GetMapping("/{roleName}")
    public JsonRequest<List<Role>> lookRolesByName(@PathVariable String roleName) {
        return roleService.lookRolesByName(roleName);
    }


    /**
     * 新增一条角色信息
     *
     * @param role 角色信息
     * @return JSON
     */
    @PostMapping
    public JsonRequest<Integer> insertOneRole(@RequestBody Role role) {
        return roleService.insertOneRole(role);
    }

    /**
     * 修改一条角色信息
     *
     * @param role 角色信息
     * @return JSON
     */
    @PutMapping
    public JsonRequest<Integer> updateOneRole(@RequestBody Role role) {
        return roleService.updateOneRole(role);
    }

    /**
     * 删除角色信息
     *
     * @param ids ID值
     * @return JSON
     */
    @DeleteMapping
    public JsonRequest<Integer> deleteRole(@RequestBody Integer[] ids) {
        return roleService.deleteRole(ids);
    }
}
